package me.hys.api.doctor;

import java.util.List;

import me.hys.api.BaseApi;
import me.hys.base.ApiResult;
import me.hys.base.PageQuery;
import me.hys.bo.doctor.CommentBo;
import me.hys.entity.doctor.CommentEntity;
import me.hys.service.doctor.ICommentManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Author: @author HYS . <br>
 * Date: 2015-10-7 下午9:43:14 . <br>
 * Function: 评论
 */
@Controller
@RequestMapping("/api/comment")
public class CommentApi extends BaseApi {
	@Autowired
	private ICommentManager commentManager;

	/**
	 * @Title : list
	 * @Description : 评论列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list/{userId}/{start}", method = RequestMethod.GET)
	public List<CommentBo> list(@PathVariable String userId,
			@PathVariable int start) {
		PageQuery<CommentBo> page = getPageQuery(start);
		page.getCondition().put("userId", userId);
		PageQuery<CommentBo> result = commentManager.findPage(page);
		return result.getList();
	}

	@ResponseBody
	@RequestMapping(value = "/post", method = RequestMethod.POST)
	public ApiResult post(@ModelAttribute CommentEntity entity) {
		return commentManager.save(entity);
	}
}
